<template>
    <div class="top-navbar">
        <div class="navbar-container">
            <!-- Logo 区域 -->
            <div class="logo-section">
                <div class="logo">
                    <span class="logo-text">云顶之弈</span>
                </div>
            </div>
            
            <!-- 导航菜单 -->
            <nav class="nav-menu">
                <div 
                    v-for="(item, index) in titleary" 
                    :key="index"
                    class="nav-item" 
                    @click="clickmsg(index)"
                    :class="{ active: tabselectindex === index }"
                >
                    <span class="nav-text">{{ item }}</span>
                    <div class="nav-indicator"></div>
                </div>
            </nav>
            
            <!-- 右侧区域（可以放置其他功能按钮） -->
            
        </div>
    </div>
</template>

<script>
import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { states } from '../utils/states'

export default {
    props: {
        titleary: {
            type: Array,
            default: []
        },
    },
    setup(props, context) {
        const router = useRouter();
        let tabselectindex = ref(0);
        
        // 根据当前路由设置正确的选中索引
        const updateTabIndex = () => {
            const currentPath = router.currentRoute.value.path;
            if (currentPath === '/home') {
                tabselectindex.value = 0;
            } else if (currentPath === '/hero') {
                tabselectindex.value = 1;
            } else if (currentPath === '/equip') {
                tabselectindex.value = 2;
            } else if (currentPath === '/bond') {
                tabselectindex.value = 3;
            } else if (currentPath === '/rune') {
                tabselectindex.value = 4;
            }
        };
        
        // 监听路由变化
        watch(() => router.currentRoute.value.path, () => {
            updateTabIndex();
        }, { immediate: true });
        
        // 监听states变化
        watch(() => states.current.path, () => {
            updateTabIndex();
        }, { immediate: true });
        
        let clickmsg = (index) => {
            tabselectindex.value = index;
            context.emit('select', tabselectindex.value);
        }
        
        return {
            tabselectindex,
            clickmsg,
        }
    }
}
</script>

<style scoped>
.top-navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(15px);
    box-shadow: 0 2px 20px rgba(0, 163, 131, 0.2);
    border-bottom: 1px solid rgba(0, 163, 131, 0.3);
}

.navbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 70px;
}

.logo-section {
    flex-shrink: 0;
}

.logo {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.logo-text {
    font-size: 24px;
    font-weight: bold;
    color: #00a383;
    text-shadow: 0 0 10px rgba(0, 163, 131, 0.5);
    line-height: 1;
}

.logo-subtitle {
    font-size: 12px;
    color: #8cc8c8;
    margin-top: -2px;
    letter-spacing: 2px;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 40px;
    flex: 1;
    justify-content: center;
}

.nav-item {
    position: relative;
    padding: 15px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-item:hover {
    background: rgba(0, 163, 131, 0.2);
    border-color: rgba(0, 163, 131, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 163, 131, 0.3);
}

.nav-item.active {
    background: rgba(0, 163, 131, 0.3);
    border-color: #00a383;
    box-shadow: 0 5px 20px rgba(0, 163, 131, 0.4);
}

.nav-text {
    font-size: 16px;
    font-weight: 500;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.nav-item:hover .nav-text,
.nav-item.active .nav-text {
    color: #00a383;
    text-shadow: 0 0 8px rgba(0, 163, 131, 0.6);
}

.nav-indicator {
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #00a383, #00d4aa);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.nav-item:hover .nav-indicator,
.nav-item.active .nav-indicator {
    width: 80%;
}

.navbar-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.search-hint {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.search-hint span {
    font-size: 12px;
    color: #8cc8c8;
    font-style: italic;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navbar-container {
        padding: 0 15px;
        height: 60px;
    }
    
    .nav-menu {
        gap: 20px;
    }
    
    .nav-item {
        padding: 10px 15px;
    }
    
    .nav-text {
        font-size: 14px;
    }
    
    .logo-text {
        font-size: 20px;
    }
    
    .search-hint {
        display: none;
    }
}

@media (max-width: 480px) {
    .nav-menu {
        gap: 10px;
    }
    
    .nav-item {
        padding: 8px 12px;
    }
    
    .nav-text {
        font-size: 13px;
    }
}
</style>